//
//  HS_EssenceOneTableViewCell.m
//  悦享
//
//  Created by 韩双 on 16/3/25.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HS_EssenceOneTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface HS_EssenceOneTableViewCell ()

@property (nonatomic, retain) UIImageView *topImage;    /**< 头条图片 */
@property (nonatomic, retain) UILabel *titleLable;    /**< 标题 */
@property (nonatomic, retain) UIImageView *timeImage;   /**< 时间标签 */
@property (nonatomic, retain) UILabel *timeLable;   /**< 时间 */

@end

@implementation HS_EssenceOneTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
}

- (void)createSubviews {
    
    self.topImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_topImage];
    
    self.titleLable = [[UILabel alloc] init];
    [self.topImage addSubview:_titleLable];
    
    self.timeImage = [[UIImageView alloc] init];
    [self.topImage addSubview:_timeImage];
    
    self.timeLable = [[UILabel alloc] init];
    [self.timeImage addSubview:_timeLable];
    
}

- (void)setModel:(HS_EssenceModel *)model {
    
    _model = model;
    
    [_topImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(8, 0, 8, 0));
        
    }];
    _topImage.backgroundColor = [UIColor redColor];
    
    [_topImage sd_setImageWithURL:[NSURL URLWithString:_model.image_url] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.contentView).with.offset(15);
        make.right.mas_equalTo(self.contentView).with.offset(-15);
        make.bottom.mas_equalTo(self.contentView).with.offset(-10);
        make.height.mas_equalTo(60);
        
    }];
    
    _titleLable.font = [UIFont boldSystemFontOfSize:20];
    _titleLable.numberOfLines = 3;
    _titleLable.textColor = [UIColor whiteColor];
    _titleLable.text = _model.title;
    
    _timeImage.image = [UIImage imageNamed:@"iconfont-mark"];
    [_timeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.contentView).with.offset(0);
        make.top.mas_equalTo(self.contentView).with.offset(20);
        make.size.mas_equalTo(CGSizeMake(50, 20));
        
    }];
    
    [_timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(_timeImage).with.insets(UIEdgeInsetsMake(0, 0, 0, -5));
        
    }];
    //    2016-03-24 18:29

    NSString *month = [_model.datetime substringWithRange:NSMakeRange(5, 2)];
    NSString *day = [_model.datetime substringWithRange:NSMakeRange(8, 2)];
    
    _timeLable.text = [NSString stringWithFormat:@"%@月%@日", month, day];
    _timeLable.font = [UIFont systemFontOfSize:10];
    _timeLable.textColor = [UIColor whiteColor];
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
